<?php
defined('PHPFOX') or exit('NO DICE!');
require_once (PHPFOX_DIR . 'module' . PHPFOX_DS . 'contactimporter' . PHPFOX_DS . 'include' . PHPFOX_DS . 'service' . PHPFOX_DS . 'libs.class.php');
class Contactimporter_Service_Abstract extends Younet_Service
{    
    protected $_sService = '';  
    protected $_host = '';  

    public function __construct()    
    {
        
    }
    
    public function processEmailRows($aRows)    
    {        
        $aResults = array();
        foreach ($aRows as $i => $aRow)
        {
            $name = $aRow['name'];
            $email = $aRow['email'];
            $char = strtoupper(substr($name, 0, 1));
            if (is_numeric($char))
            {
                $aResults['Z'][] = array('email' => $email, 'name' => $name);
            }
            else
            {               
                for ($start = ord('A'); $start <= ord('Z'); $start++)
                {
                    if (ord($char) == $start)
                    {
                        $aResults[chr($start)][] = array('email' => $email, 'name' => $name);
                        break;
                    }
                    else
                    {
                        if (!isset($aResults[chr($start)])) 
                        {   
                            $aResults[chr($start)] = array();
                        }
                    }
                }
            }
        }
        ksort($aResults);
        return $aResults;
    }
    
    public function processSocialRows($aRows)    
    {        
        $aResults = array();
        foreach ($aRows as $i => $aRow)
        {
            if (isset($aRow['profile_image_url']))
            {
                $aRows[$i]['pic'] = $aRow['pic'] = $aRow['profile_image_url'];
            }
            $name = $aRow['name'];
            $id = $aRow['id'];
            $pic = $aRow['pic'];
            $char = strtoupper(substr($name, 0, 1));
            if (is_numeric($char))
            {
                $aResults['Z'][] = array('name' => $name, 'id' => $id, 'pic' => $pic);
            }
            else
            {               
                for ($start = ord('A'); $start <= ord('Z'); $start++)
                {
                    if (ord($char) == $start)
                    {
                        $aResults[chr($start)][] = array('name' => $name, 'id' => $id, 'pic' => $pic);
                        break;
                    }
                    else
                    {
                        if (!isset($aResults[chr($start)])) 
                        {   
                            $aResults[chr($start)] = array();
                        }
                    }
                }
            }
        }
        ksort($aResults);
        return $aResults;
    }
}
?>